home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: uu4news.netcom.com!amc-gw!curtis
- From: curtis@amc.com (Curtis Green)
- Subject: Re: cin.get(string) problem
- Message-ID: <1996Feb14.011237.14914@amc.com>
- Organization: Applied Microsystems Corporation
- X-Newsreader: TIN [version 1.1 PL6]
- References: <4fk02a$nh@reader2.ix.netcom.com>
- Date: Wed, 14 Feb 1996 01:12:37 GMT
-
- Kurt W. Greiner (greinerk@ix.netcom.com) wrote:
- : Hi all,
- : i was trying some really simple io for a program that just gets
- : values, here is a sample of code
- :
- : #include <iostream.h>
- :
- : void main(void)
- : {
- : char string[80];
- : cin.get(string,sizeof(string));
- : cin.get(string,sizeof(string));
- : }
- :
- : ok, say i want to read in a name on the first cin, i type in "john smith" and
- : the prompt, john gets thrown in to the first and smith the second, i do not
- : even get prompted for the second cin. it does not happen if i type in a string
- : with out spaces. i am using borland c++ 2.0, am i doing something wrong or is
- : there an other way of doing this other than gets(string)?
- :
- : kurt
-
- Might be a problem with whitespace. "john smith" has a whitespace delimiter
- between "john" and "smith", to the get method sees the space and quits input.
- Try getline(). that should default to a '\n' delimiter.
-
- void main(void)
- {
- char string[80];
- cin.getline(string,sizeof(string));
- cin.getline(string,sizeof(string));
- }
-
- will do what you want
-
-
- --
- Be seeing you...
-
- Curtis Green | Software Engineer
- curtis@amc.com | Applied Microsystems Embedded Systems
- | http://www.amc.com
- My opinions are |
- expressly mine | This year Khan escapes Earth on the Botany Bay.
- on my own. | (Cliff Clavin, 1996)
-